
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>Spring Integration | Metrics</title>
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css"/>
    <link rel="stylesheet" href="../../_static/yammerdoc.css" type="text/css"/>
    <link rel="top" title="Metrics" href="../../"/>
    <link rel="up" title="User Manual" href="../"/>
    <link rel="next" title="Instrumenting Web Applications" href="../webapps/"/>
    <link rel="prev" title="Metrics Servlets" href="../servlet/"/>
    <style lang="text/css">
        #top-bar, #top-bar small, #top-bar a {
            text-shadow: 0px -1px 0px #cf2c0f;
            color: #fff;
        }
        
        #top-bar {
            background-color: #ED4A2D;
            background-image: -moz-linear-gradient(top, #ff684b, #cf2c0f);
            background-image: -ms-linear-gradient(top, #ff684b, #cf2c0f);
            background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ff684b), to(#cf2c0f));
            background-image: -webkit-linear-gradient(top, #ff684b, #cf2c0f);
            background-image: -o-linear-gradient(top, #ff684b, #cf2c0f);
            background-image: linear-gradient(top, #ff684b, #cf2c0f);
            filter: progid:DXImageTransform.Microsoft.gradient(startColorstr = '#ff684b', endColorstr = '#cf2c0f', GradientType = 0);
            -webkit-border-radius: 0;
            -moz-border-radius: 0;
            border-radius: 0;
        }


        .hero-unit {
            background-image: url("../../_static/metrics-hat.png") !important;
            background-repeat: no-repeat !important;
            background-position: 30px 50px;
        }

        .hero-unit div.section {
            padding-left: 200px !important;
        }
    </style>
</head>
<body>
    <a href="https://github.com/dropwizard/metrics">
        <img style="position: absolute; top: 0; right: 0; border: 0;"
             src=""
             alt="Fork me on GitHub"></a>
    <div class="navbar">
        <div class="navbar-inner container-fluid" id="top-bar">
            <header class="row-fluid">
                <h1 class="span12" id="title"><img class="logo" src="../../_static/metrics-logo.png" alt="Logo"/>
                    <a href="../../">Metrics</a>
                    <small>Mind the gap.</small>
                </h1>
            </header>
        </div>
    </div>
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="span3" id="sidebar">
                <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../getting-started/">Getting Started</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../">User Manual</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../core/">Metrics Core</a></li>
<li class="toctree-l2"><a class="reference internal" href="../ehcache/">Instrumenting Ehcache</a></li>
<li class="toctree-l2"><a class="reference internal" href="../ganglia/">Reporting to Ganglia</a></li>
<li class="toctree-l2"><a class="reference internal" href="../graphite/">Reporting to Graphite</a></li>
<li class="toctree-l2"><a class="reference internal" href="../guice/">Guice Integration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../httpclient/">Instrumenting Apache HttpClient</a></li>
<li class="toctree-l2"><a class="reference internal" href="../jdbi/">Instrumenting JDBI</a></li>
<li class="toctree-l2"><a class="reference internal" href="../jersey/">Instrumenting Jersey</a></li>
<li class="toctree-l2"><a class="reference internal" href="../jetty/">Instrumenting Jetty</a></li>
<li class="toctree-l2"><a class="reference internal" href="../log4j/">Instrumenting Log4j</a></li>
<li class="toctree-l2"><a class="reference internal" href="../logback/">Instrumenting Logback</a></li>
<li class="toctree-l2"><a class="reference internal" href="../scala/">Scala Support</a></li>
<li class="toctree-l2"><a class="reference internal" href="../servlet/">Metrics Servlets</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="">Spring Integration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../webapps/">Instrumenting Web Applications</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../about/">About Metrics</a></li>
</ul>

                <hr/>
                <ul>
                    <li><a href="https://groups.google.com/forum/#!forum/metrics-user">Mailing List</a></li>
                    <li><a href="https://dropwizard.github.io/metrics/2.2.0/maven/">Maven Site</a></li>
                </ul>
            </div>
            <div class="span9" id="body">
                
  <div class="section" id="spring-integration">
<span id="manual-spring"></span><h1>Spring Integration</h1>
<p>The <tt class="docutils literal"><span class="pre">metrics-spring</span></tt> module enables the use of Metrics annotations with
<a class="reference external" href="http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/aop.html">Spring AOP</a>, complete with simple XML configuration:</p>
<div class="highlight-xml"><div class="highlight"><pre><span class="nt">&lt;beans</span> <span class="na">xmlns=</span><span class="s">&quot;http://www.springframework.org/schema/beans&quot;</span>
       <span class="na">xmlns:xsi=</span><span class="s">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>
       <span class="na">xmlns:metrics=</span><span class="s">&quot;http://www.yammer.com/schema/metrics&quot;</span>
       <span class="na">xsi:schemaLocation=</span><span class="s">&quot;</span>
<span class="s">           http://www.yammer.com/schema/metrics http://www.yammer.com/schema/metrics/metrics.xsd</span>
<span class="s">           http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd&quot;</span><span class="nt">&gt;</span>

    <span class="nt">&lt;metrics:metrics-registry</span> <span class="na">id=</span><span class="s">&quot;metrics&quot;</span><span class="nt">/&gt;</span>
    <span class="nt">&lt;metrics:health-check-registry</span> <span class="na">id=</span><span class="s">&quot;health&quot;</span><span class="nt">/&gt;</span>

    <span class="nt">&lt;metrics:annotation-driven</span> <span class="na">metrics-registry=</span><span class="s">&quot;metrics&quot;</span> <span class="na">health-check-registry=</span><span class="s">&quot;health&quot;</span><span class="nt">/&gt;</span>

    <span class="nt">&lt;metrics:jmx-reporter</span> <span class="na">id=</span><span class="s">&quot;metricsJmxReporter&quot;</span> <span class="na">metrics-registry=</span><span class="s">&quot;metrics&quot;</span><span class="nt">/&gt;</span>

    <span class="c">&lt;!-- other beans --&gt;</span>

<span class="nt">&lt;/beans&gt;</span>
</pre></div>
</div>
<p>The most important part of the configuration is the element <tt class="docutils literal"><span class="pre">&lt;metrics:annotation-driven</span> <span class="pre">/&gt;</span></tt>.
This registers custom Spring bean processors, which serve three main purposes:</p>
<ul class="simple">
<li>Proxying beans which have methods annotated with <tt class="docutils literal"><span class="pre">&#64;Timed</span></tt>, <tt class="docutils literal"><span class="pre">&#64;Metered</span></tt>, and <tt class="docutils literal"><span class="pre">&#64;ExceptionMetered</span></tt>.</li>
<li>Registering a <tt class="docutils literal"><span class="pre">Gauge</span></tt> for beans which have members annotated with <tt class="docutils literal"><span class="pre">&#64;Gauge</span></tt>.</li>
<li>Registering beans which extend the class <tt class="docutils literal"><span class="pre">HealthCheck</span></tt>.</li>
</ul>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Due to a limitation in Spring AOP, only public methods can be proxied, so <tt class="docutils literal"><span class="pre">&#64;Timed</span></tt>, <tt class="docutils literal"><span class="pre">&#64;Metered</span></tt>, and <tt class="docutils literal"><span class="pre">&#64;ExceptionMetered</span></tt> have no effect on non-public methods.
As <tt class="docutils literal"><span class="pre">&#64;Gauge</span></tt> doesn&#8217;t involve a proxy, it is possible to use this annotation on private fields and methods.</p>
</div>
<p>The <tt class="docutils literal"><span class="pre">&lt;metrics:annotation-driven</span> <span class="pre">/&gt;</span></tt> element accepts 5 optional arguments:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">metrics-registry</span></tt>: the name of the <tt class="docutils literal"><span class="pre">MetricsRegsitry</span></tt> bean with which the generated metrics should be registered.  If omitted, this defaults to registry provided by <tt class="docutils literal"><span class="pre">Metrics.defaultRegistry()</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">health-check-registry</span></tt>: the name of the <tt class="docutils literal"><span class="pre">HealthCheckRegsitry</span></tt> bean with which to register any beans which extend the class <tt class="docutils literal"><span class="pre">HealthCheck</span></tt>. If omitted, this defaults to registry provided by <tt class="docutils literal"><span class="pre">HealthChecks.defaultRegistry()</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">scope</span></tt>: sets the scope for each of the metrics.</li>
<li><tt class="docutils literal"><span class="pre">proxy-target-class</span></tt>: if set to <tt class="docutils literal"><span class="pre">true</span></tt>, always creates CGLIB proxies instead of defaulting to JDK proxies. This is necessary if you use class-based autowiring.</li>
<li><tt class="docutils literal"><span class="pre">expose-proxy</span></tt>: if set to <tt class="docutils literal"><span class="pre">true</span></tt>, the target can access the proxy which wraps it by calling <tt class="docutils literal"><span class="pre">AopContext.currentProxy()</span></tt>.</li>
</ul>
<p>The elements <tt class="docutils literal"><span class="pre">&lt;metrics:metrics-registry</span> <span class="pre">/&gt;</span></tt> and <tt class="docutils literal"><span class="pre">&lt;metrics:health-check-registry</span> <span class="pre">/&gt;</span></tt> are present as a convenience for creating new registry beans.</p>
<p>The element <tt class="docutils literal"><span class="pre">&lt;metrics:jmx-reporter</span> <span class="pre">/&gt;</span></tt> creates a JMX Reporter for the specified metrics registry. A JMX Reporter is automatically created for the default metrics registry.</p>
</div>


            </div>
        </div>
        <hr/>
        <footer>
            &copy; Copyright 2010-2012, Coda Hale, Yammer Inc..
            Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>
            1.2.2.
        </footer>
    </div>
</body>
</html>


